<?php 

/*====================================================
 Author: RooTM
------------------------------------------------------
 Web-site: http://weboss.net/
=====================================================*/

if( ! defined( 'DATALIFEENGINE' ) ) {
	die( "Hacking attempt!" );
}

include ENGINE_DIR . '/modules/iChat/data/config.php';
require_once ENGINE_DIR.'/modules/iChat/language/website.lng';
require_once ENGINE_DIR.'/modules/iChat/functions.php';

require_once ENGINE_DIR . '/classes/templates.class.php';

$tpl = new dle_template ( );
$tpl->dir = ENGINE_DIR . '/modules/iChat/template/';
define ( 'TEMPLATE_DIR', $tpl->dir );

$is_change = false;

if ($config['allow_cache'] != "yes") { $config['allow_cache'] = "yes"; $is_change = true;}

$Messages = dle_cache( "iChat", $config['skin'] );

include ENGINE_DIR . '/modules/iChat/build.php';

echo "\n\n<!-- iChat by RooTM (http://weboss.net/) -->\n\n";

echo <<<HTML
<form  method="post" name="iChat_form" id="iChat_form" action="/">   

<link rel="stylesheet" type="text/css" href="/engine/modules/iChat/template/css/style.css" />

<script type="text/javascript" src="/engine/modules/iChat/template/js/edit.js"></script>
<script type="text/javascript" src="/engine/modules/iChat/template/js/bbcode.js"></script>

<script type="text/javascript">
var iChat_lang_edit_msg = "{$chat_lang['edit_msg']}";
var iChat_lang_new_text_msg = "{$chat_lang['new_text_msg']}";
var iChat_lang_title = "{$chat_lang['title']}";
var iChat_lang_null = "{$chat_lang['null']}";
var iChat_lang_max = "{$chat_lang['max']}";
var iChat_max_text = {$chat_cfg['max_text']};
var iChat_Refresh_time = {$chat_cfg['refresh']}*1000;
setInterval(iChatRefresh, iChat_Refresh_time);
</script>
HTML;

$tpl->load_template ( 'skin.tpl' );

$tpl->set ( '{messages}', $Messages );
$tpl->set ( '{THEME}', "/engine/modules/iChat/template" );

$tpl->compile ( 'skin' );

if( $user_group[$member_id['user_group']]['allow_url'] ) $tpl->result['skin'] = preg_replace( "'\[allow_url\](.*?)\[/allow_url\]'si", "\\1", $tpl->result['skin'] );
else $tpl->result['skin'] = preg_replace ( "'\[allow_url\](.*?)\[/allow_url\]'si", "", $tpl->result['skin'] );

echo $tpl->result['skin'];

$tpl->global_clear ();

if( $is_logged == TRUE  ) {
	$i = 0;
$all_smiles = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr>";

    $smilies = explode(",", $chat_cfg['smiles']);
	$count_smilies = count($smilies);

    foreach($smilies as $smile)
    {
        $i++; $smile = trim($smile);

        $all_smiles .= "<td style=\"padding:2px;\" align=\"center\"><a href=\"#\" onclick=\"iChat_smiley(':$smile:'); return false;\"><img style=\"border: none;\" alt=\"$smile\" src=\"".$config['http_home_url']."engine/data/emoticons/$smile.gif\" /></a></td>";

		if ($i%4 == 0 AND $i < $count_smilies) $all_smiles .= "</tr><tr>";

    }

	$all_smiles .= "</tr></table>";

echo '<div id="iChat_emos" style="display: none;" title="Вставка смайликов"><div style="width:100%;height:100%;overflow: auto;">'.$all_smiles.'</div></div>';
}

echo "</form>";

echo "\n\n<!-- iChat by RooTM (http://weboss.net/) -->\n\n";

if ($is_change) $config['allow_cache'] = false;

?>
